package stephen.com.utils;


import stephen.com.constant.Const;

public class PageUtil {

    public static long getSumPage(long totalCount) {
        return totalCount % Const.MAX_RECORD_COUNT == 0 ? totalCount / Const.MAX_RECORD_COUNT : totalCount / Const.MAX_RECORD_COUNT + 1;
    }

    public static long getStartPage(long currentPage) {
        long start = currentPage % Const.PAGE_GROUP_COUNT == 0 ? currentPage / Const.PAGE_GROUP_COUNT : currentPage / Const.PAGE_GROUP_COUNT + 1;
        return (start - 1) * Const.PAGE_GROUP_COUNT;
    }

    public static long getEndPage(long currentPage, long totalPage) {
        long startPage = getStartPage(currentPage);
        if (startPage + Const.PAGE_GROUP_COUNT <= totalPage) {
            return startPage + Const.PAGE_GROUP_COUNT;
        } else {
            return totalPage;
        }
    }

}
